package com.ruoyi.zhongchuangauto.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.zhongchuangauto.domain.ExcelImportDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhongchuangauto.domain.SplitOrder;
import com.ruoyi.zhongchuangauto.service.ISplitOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 待分单订单Controller
 *
 * @author ruoyi
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/zhongchuangauto/zcsplitorder")
public class SplitOrderController extends BaseController
{
    @Autowired
    private ISplitOrderService splitOrderService;

    /**
     * 查询待分单订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(SplitOrder splitOrder)
    {
        startPage();
        List<SplitOrder> list = splitOrderService.selectSplitOrderList(splitOrder);
        return getDataTable(list);
    }

    /**
     * 导出待分单订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:export')")
    @Log(title = "待分单订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SplitOrder splitOrder)
    {
        List<SplitOrder> list = splitOrderService.selectSplitOrderList(splitOrder);
        ExcelUtil<SplitOrder> util = new ExcelUtil<SplitOrder>(SplitOrder.class);
        util.exportExcel(response, list, "待分单订单数据");
    }

    /**
     * 获取待分单订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(splitOrderService.selectSplitOrderByOrderId(orderId));
    }

    /**
     * 新增待分单订单
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:add')")
    @Log(title = "待分单订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SplitOrder splitOrder)
    {
        return toAjax(splitOrderService.insertSplitOrder(splitOrder));
    }

    /**
     * 修改待分单订单
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:edit')")
    @Log(title = "待分单订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SplitOrder splitOrder)
    {
        return toAjax(splitOrderService.updateSplitOrder(splitOrder));
    }

    /**
     * 删除待分单订单
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:remove')")
    @Log(title = "待分单订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(splitOrderService.deleteSplitOrderByOrderIds(orderIds));
    }

    /**
     * 上传分单文件信息
     */
    @PreAuthorize("@ss.hasPermi('zhongchuangauto:zcsplitorder:add')")
    @Log(title = "分单订单内容处理", businessType = BusinessType.OTHER)
    @PostMapping("/uploadZcsplit")
    public AjaxResult uploadZcsplit(@RequestBody ExcelImportDto dto)
    {
        return AjaxResult.success(splitOrderService.uploadZcsplit(dto.getFileUrl()));
    }
}
